<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>好友留言板</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #e0f7fa 0%, #bbdefb 100%);
            padding: 20px;
            min-height: 100vh;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.7);
            backdrop-filter: blur(10px);
            padding: 30px;
            border-radius: 16px;
            box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
            border: 1px solid rgba(255, 255, 255, 0.3);
        }
        
        h1 {
            text-align: center;
            color: #006064;
            margin-bottom: 30px;
            font-weight: 600;
            text-shadow: 0 1px 2px rgba(0,0,0,0.1);
        }
        
        .message-form {
            margin-bottom: 30px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            color: #01579b;
            font-weight: 600;
        }
        
        input[type="text"],
        textarea {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid rgba(2, 119, 189, 0.3);
            border-radius: 8px;
            font-size: 16px;
            background: rgba(255, 255, 255, 0.6);
            transition: all 0.3s ease;
        }
        
        input[type="text"]:focus,
        textarea:focus {
            outline: none;
            border-color: #0288d1;
            box-shadow: 0 0 0 3px rgba(2, 136, 209, 0.2);
        }
        
        textarea {
            resize: vertical;
            min-height: 120px;
        }
        
        button {
            background: linear-gradient(to right, #00838f, #006064);
            color: white;
            padding: 12px 25px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 99, 100, 0.2);
        }
        
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0, 99, 100, 0.3);
        }
        
        .message-list {
            margin-top: 30px;
        }
        
        .message-item {
            background: rgba(255, 255, 255, 0.5);
            padding: 20px;
            margin-bottom: 20px;
            border-radius: 12px;
            border-left: 4px solid #00838f;
            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
            transition: transform 0.3s ease;
        }
        
        .message-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
        }
        
        .message-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 12px;
            align-items: center;
        }
        
        .message-author {
            font-weight: bold;
            color: #006064;
            font-size: 18px;
        }
        
        .message-time {
            color: #0288d1;
            font-size: 14px;
            font-weight: 500;
        }
        
        .message-content {
            color: #37474f;
            line-height: 1.6;
            font-size: 16px;
        }
        
        .no-messages {
            text-align: center;
            color: #0288d1;
            padding: 30px;
            font-size: 18px;
            background: rgba(255, 255, 255, 0.4);
            border-radius: 12px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>📝 好友留言板</h1>
        
        <div class="message-form">
            <form id="messageForm">
                <div class="form-group">
                    <label for="nickname">你的昵称：</label>
                    <input type="text" id="nickname" name="nickname" required placeholder="请输入你的昵称">
                </div>
                
                <div class="form-group">
                    <label for="message">留言内容：</label>
                    <textarea id="message" name="message" required placeholder="写下你想说的话..."></textarea>
                </div>
                
                <button type="submit">发表留言</button>
            </form>
        </div>
        
        <div class="message-list" id="messageList">
            <div class="no-messages">暂无留言，快来发表第一条留言吧！</div>
        </div>
    </div>

    <script>
        // 从localStorage获取留言
        let messages = JSON.parse(localStorage.getItem('messages')) || [];
        
        // 显示留言
        function displayMessages() {
            const messageList = document.getElementById('messageList');
            
            if (messages.length === 0) {
                messageList.innerHTML = '<div class="no-messages">暂无留言，快来发表第一条留言吧！</div>';
                return;
            }
            
            messageList.innerHTML = '';
            
            // 按时间倒序排列
            messages.sort((a, b) => new Date(b.time) - new Date(a.time));
            
            messages.forEach((msg, index) => {
                const messageItem = document.createElement('div');
                messageItem.className = 'message-item';
                messageItem.innerHTML = `
                    <div class="message-header">
                        <span class="message-author">${msg.nickname}</span>
                        <span class="message-time">${formatTime(msg.time)}</span>
                    </div>
                    <div class="message-content">${msg.content}</div>
                `;
                messageList.appendChild(messageItem);
            });
        }
        
        // 格式化时间
        function formatTime(timeString) {
            const date = new Date(timeString);
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            
            return `${year}-${month}-${day} ${hours}:${minutes}`;
        }
        
        // 处理表单提交
        document.getElementById('messageForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const nickname = document.getElementById('nickname').value.trim();
            const message = document.getElementById('message').value.trim();
            
            if (nickname && message) {
                const newMessage = {
                    nickname: nickname,
                    content: message,
                    time: new Date().toISOString()
                };
                
                messages.push(newMessage);
                localStorage.setItem('messages', JSON.stringify(messages));
                
                // 清空表单
                document.getElementById('message').value = '';
                
                // 重新显示留言
                displayMessages();
                
                // 显示成功提示
                alert('留言发表成功！');
            }
        });
        
        // 页面加载时显示留言
        displayMessages();
    </script>
</body>
</html>